package com.pd.kit;

import java.util.Map;

/**
 * Created by dong peng
 * DATE : 2016/12/25
 * TIME : 23:42.
 *
 * 拼装url链接
 */

public class UrlLinkKit {



    public static String join(String url, Map<String,String> dataMap) {
        if(url == null) {
            return  "";
        }

        if(dataMap == null || dataMap.size() <= 0) {
            return url;
        }

        StringBuilder stb = new StringBuilder(url);
        int cur = url.indexOf("?");
        for(Map.Entry<String, String> entry : dataMap.entrySet()) {
            if(cur > -1) {
                stb.append("&" + entry.getKey() + "=" + entry.getValue());
            }else {
                stb.append("?" + entry.getKey() + "=" + entry.getValue());
                cur = 1; // 表示问号已经追加在了url后面
            }
        }

        return stb.toString();
    }
}
